<template>
  <div class="mr-sh-midSearch">
    <div class="mr-sh-midSearhchBox">
      <ul>
        <li>
          <span>条码</span>
        </li>
        <li>
          <el-input
            size="mini"
            v-model="searchData.barcode"
            placeholder="请输入内容"
             
          ></el-input>
        </li>
        <li>
          <span>零件图号</span>
        </li>
        <li>
          <el-input
            size="mini"
            v-model="searchData.tuhao"
            placeholder="请输入内容"
             
          ></el-input>
        </li>
        <li>
          <span>质量编号</span>
        </li>
        <li>
          <el-input
            size="mini"
            v-model="searchData.qualityNumber"
            placeholder="请输入内容"
          ></el-input>
        </li>
        <li>
          <span>移交人</span>
        </li>
        <li>
          <el-input
            size="mini"
            v-model="searchData.person"
            placeholder="请输入内容"
             
          ></el-input>
        </li>
        <li>
          <span>移交时间</span>
        </li>
        <li>
          <el-date-picker
            size="mini"
            v-model="searchData.startTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
          ></el-date-picker>
        </li>
        <li>
          <span>到</span>
        </li>
        <li>
          <el-date-picker
            size="mini"
            v-model="searchData.endTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            default-time="12:00:00"
          ></el-date-picker>
        </li>
        <li>
          <el-button
            size="mini"
            type="primary"
            @click="scanningSearch"
            style="margin-left: 5px"
            >查询</el-button
          >
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { scanSearch } from "@/utils/api.js"
export default {
  name: "MrShMidSearch",
  data() {
    return {
      searchData: {
        startTime: "",
        endTime: "",
        tuhao: "",
        qualityNumber: "",
        person:"",
        barcode:''
      },
      pageSize:'',
      pageNumber:1,
      indexData:true,
      indexST:'',
      indexET:''
    };
  },
  mounted() {
    this.$options.methods.getNowTime.bind(this)()
    // 接收Tables传的pageSize，pageNumber
    this.$bus.$on('shPageNumbers',(e)=>{
      this.pageSize = e
    })
    // 接收扫码的条码加到barcode输入框
    this.$bus.$on('mrShSearchBarcode',(e)=>{
      let barcode = ''
      if(this.tiaoma.includes('{')){
        barcode = JSON.parse(e).CPHGZ
      }else{
        barcode = e
      }
      this.searchData.barcode =barcode;
    })
  },
  methods: {
    getNowTime() {
      var now = new Date();
      var year = now.getFullYear(); //得到年份
      var month = now.getMonth(); //得到月份
      var date = now.getDate(); //得到日期
      month = month + 1;
      month = month.toString().padStart(2, "0");
      date = date.toString().padStart(2, "0");
      var defaultDate1 = `${year}-${month}-${date}`;
      // 减去一天的毫秒数
      now.setTime(now.getTime() + 24 * 60 * 60 * 1000);
      var month2 = now.getMonth() + 1;
      month2 = month2.toString().padStart(2, "0");
      var date2 = now.getDate()
      date2 = date2.toString().padStart(2, "0");
      // 写成yyyy-mm-dd的格式
      var yesterday = now.getFullYear() + "-" + month2 + "-" + date2;

      var defaultDate2 = yesterday;
      this.indexST = defaultDate1
      this.indexET = defaultDate2
      this.$set(this.searchData, "startTime", defaultDate1);
      this.$set(this.searchData, "endTime", defaultDate2);
    },
    // 条件查询
    scanningSearch() {
      scanSearch({
        funcType:"handOver",
        pageParameter:{
          rows:this.pageSize,
          page:1
        },
        searchParams:{
          receiveEmpCode:this.searchData.person,
		      qualityCode:this.searchData.qualityNumber,
          itemCode:this.searchData.tuhao,
          barcode:this.searchData.barcode
        },
        startTime:this.searchData.startTime,
        endTime:this.searchData.endTime,
      }).then((res)=>{
        // 接收查询按钮返回的Data,传给Table,重置数据和总条数和提供分页所需数据
        this.$bus.$emit('scanHandSearchData',{
          resData:res.data.responseBody.result,
          receiveEmpCode:this.searchData.person,
          qualityCode:this.searchData.qualityNumber,
          drawNo:this.searchData.tuhao,
          startTime:this.searchData.startTime,
          endTime:this.searchData.endTime})
        console.log("扫码移交查询按钮",res)
      })
    },
  },
  updated(){
    if(this.indexData){
      this.indexData = false
      scanSearch({
        funcType:"handOver",
        pageParameter:{
          rows:this.pageSize,
          page:1
        },
        searchParams:{
          receiveEmpCode:this.searchData.person,
		      qualityCode:this.searchData.qualityNumber
        },
        drawNo:this.searchData.tuhao,
        startTime:this.indexST,
        endTime:this.indexET,
      }).then((res)=>{
        // 接收查询按钮返回的Data,传给Table,重置数据和总条数和提供分页所需数据
        this.$bus.$emit('scanHandSearchData',{
          resData:res.data.responseBody.result,
          receiveEmpCode:this.searchData.person,
          qualityCode:this.searchData.qualityNumber,
          drawNo:this.searchData.tuhao,
          startTime:this.searchData.startTime,
          endTime:this.searchData.endTime})
        console.log("扫码移交查询按钮",res)
      })
    }
    
  }
};
</script>
<style scoped>
.mr-sh-midSearch {
  overflow: hidden;
  /* border-left: 1px solid rgb(204, 204, 204);
  border-right: 1px solid rgb(204, 204, 204); */
  /* border-bottom: 1px solid rgb(204, 204, 204); */
  font-size: 14px;
}
.mr-sh-midSearhchBox {
  padding: 5px 2px;
}
.mr-sh-midSearhchBox ul li {
  height: 35px;
  float: left;
  margin-right: 10px;
  line-height: 35px;
}
.mr-sh-midSearhchBox ul li .el-input {
  width: 125px;
}
</style>